package com.hd123.rumba.gwt.widget.client;

import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.TextBox;

public class TextButtonBox extends Composite {
  TextBox textBox;
  Image button;

  public TextButtonBox() {
    super();
    HorizontalPanel hp = new HorizontalPanel();
    hp.setSpacing(0);
    hp.add(textBox = new TextBox());
    hp.setCellWidth(textBox, "100%");
    hp.add(button = new Image("images/editor-button.gif"));
    initWidget(hp);
  }

  public void setWidth(String width) {
    super.setWidth(width);
    textBox.setWidth("100%");
  }

  public void setReadOnly(boolean b) {
    textBox.setReadOnly(b);
  }

  public boolean isReadOnly() {
    return textBox.isReadOnly();
  }

  public int getCursorPos() {
    return textBox.getCursorPos();
  }

  public void setText(String text) {
    textBox.setText(text);
  }

  public String getText() {
    return textBox.getText();
  }

  public void setFocus(boolean focused) {
    if (focused) {
      Util.focusTextBox(textBox);
    } else {
      textBox.setFocus(false);
    }
  }

  public Image getButton() {
    return button;
  }

  public TextBox getTextBox() {
    return textBox;
  }
}
